/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package deatax.display.gui;

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JTextField;

/**
 *
 * @author nrechten
 */
public class JLabeledTextField extends JTextField {
    private String emptyText = "";
    private Color foregroundColour = Color.BLACK;
//    private boolean isEmpty = true;

    public static Color EMPTY_COLOUR = Color.LIGHT_GRAY;

    public JLabeledTextField() {
    }

    
    @Override
    public void setText(String value){
//        if(value == null || value.isEmpty()){
//            isEmpty = true;
//        }
        super.setText(value);
    }

    /**
     * @return the emptyText
     */
    public String getEmptyText() {
        return emptyText;
    }

    /**
     * @param emptyText the emptyText to set
     */
    public void setEmptyText(String emptyText) {
        this.emptyText = emptyText;
    }

    /**
     * @return the foregroundColour
     */
    public Color getForegroundColour() {
        return foregroundColour;
    }

    /**
     * @param foregroundColour the foregroundColour to set
     */
    public void setForegroundColour(Color foregroundColour) {
        this.foregroundColour = foregroundColour;
    }

    @Override
    public void paintComponent(Graphics g) {
        
        super.paintComponent(g);
        if(getText().isEmpty()){
            g.setColor(EMPTY_COLOUR);
            g.drawString(emptyText, this.getInsets().left + 1, this.getBaseline(this.getWidth(), this.getHeight()));
        }
    }

}
